<template>
  <el-container class="wrapper">
    <el-row class="menu" justify="end" type="flex">
      <el-col class="menu-item" @click.native="exit">
        <i class="el-icon-switch-button"></i>
        <span style="margin-left: 10px">注销</span></el-col>
    </el-row>
  </el-container>
</template>

<script>
export default {
  name: "toolbar",
  data() {
    return {}
  },
  methods: {
    exit: function () {
      this.$axios.post("/api/user/logout")
        .then(res => {
          const code = res.data.statusCode;
          if (code === 200) {
            this.$message.success("注销成功！即将回到登录界面！");
            const redirect = "/login";
            const waitTime = 1;
            setTimeout(() => {
              this.$router.push(redirect);
            }, waitTime * 1000);
          } else {
            this.$message.error("注销失败！");
          }
        })
    }
  }
}
</script>

<style lang="scss" scoped>

.wrapper {
  background-color: #393D49;
  height: 100%;
  width: 100%;
}

.menu {
  width: 100%;
  background-color: #393D49;
  border: none;
}

.menu-item {
  width: fit-content;
  color: white;
  height: 100%;
  padding: 0 30px;
  transition: width .3s, background-color .3s, color .3s;
  cursor: pointer;
  line-height: 60px;

  &:hover {
    background-color: #292D39;
    color: #ffd04b;
  }
}

</style>